import axios from 'axios'
export const requestCommon = (url, params, method = 'post') => {
  return axios[method](url, params, {
    headers: {
      'token': 'a14a283fa1026472414bf8eb632d147b'
    }
  }).then(res => res.data)
}

export const ERR_OK = 200
export const ERR_OK2 = 1

export const requestCurry = (pageNum, listNum, funcSuccess, funcError, deep, type) => {
  var requsetObj
  if (type) {
    requsetObj = {
      pagenum: pageNum,
      listNum: listNum,
      type: type
    }
  } else {
    requsetObj = {
      pagenum: pageNum,
      listNum: listNum
    }
  }
  if (!deep) {
    return (url, method) => {
      requestCommon(url, requsetObj, method).then(funcSuccess).catch(funcError)
    }
  } else {
    return (url, paraObj, method) => {
      let requsetRes = Object.assign({}, requsetObj, paraObj)
      requestCommon(url, requsetRes, method).then(funcSuccess).catch(funcError)
    }
  }
}

export const curryGetRequest = (funcSuccess, funcError) => {
  return (url, requestObj, method) => {
    requestCommon(url, requestObj, method).then(funcSuccess).catch(funcError)
  }
}
